import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {
    name: "Login",
    path: "/login",
    component: () => import("../view/login/login.vue"),
  },
  {
    name: "Home",
    path: "/home",
    component: () => import("../view/home/home.vue"),
  },
  {
    name: "Gdszz",
    path: "/gdszz",
    component: () => import("../view/gdszz/gdszz.vue"), //广东省中职
  },
  {
    name: "Pz",
    path: "/pz",
    component: () => import("../view/pz/pz.vue"), //普职
  },
  {
    name: "Qgzz",
    path: "/qgzz",
    component: () => import("../view/qgzz/qgzz.vue"), //全国中职
  },
  {
    name: "Xmqk",
    path: "/xmqk",
    component: () => import("../view/xmqk/xmqk.vue"), //项目情况
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  if(to.path=='/login'){
    next();
  }else{
    if(localStorage.getItem('token')){
      if(to.path=='/'){
        next('home')
      }else{
        next()
      }
    }else{
      next('/login');
    }
  }
});
router.afterEach((to, from) => {
  // console.log(to,from,next,'跳转后')
});

export default router;
